package com.myself.common.model


data class ResultData<T>(
    val status: Int,
    val message: String,
    var data: T? = null,
    val timestamp: Long = System.currentTimeMillis()
) {
    /** 结果状态 ,具体状态码参见ResultData.java */
    companion object {
        fun <T> success(data: T): ResultData<T> {
            return ResultData<T>(
                status = ReturnCode.RC200.code,
                data = data,
                message = ReturnCode.RC200.message,
            )
        }

        fun <T> fail(code: Int, message: String): ResultData<T> {
            return ResultData<T>(
                status = code,
                message = message,
            )
        }
    }
}


enum class ReturnCode(
    /**自定义状态码 */
    val code: Int,
    /**自定义描述 */
    val message: String
) {
    /** Operation failed */
    RC999(999, "Operation failed"),

    /** Operation succeeded */
    RC200(200, "Operation succeeded"),

    /** Service degraded */
    RC201(201, "Service is in degradation protection mode, please try again later!"),

    /** Hot parameter rate limiting */
    RC202(202, "Hot parameter rate limiting, please try again later!"),

    /** System rule not satisfied */
    RC203(203, "System rule requirements not satisfied, please try again later!"),

    /** Authorization rule failed */
    RC204(204, "Authorization rule failed, please try again later!"),

    /** Access denied */
    RC403(403, "Access denied, please contact the administrator for permission"),

    /** Access denied for anonymous user */
    RC401(401, "登录过期 请重新登录"),

    /** Service error */
    RC500(500, "System error, please try again later"),

    /** Invalid token */
    INVALID_TOKEN(2001, "The access token is invalid"),

    /** Access denied */
    ACCESS_DENIED(2003, "No permission to access the resource"),

    /** Client authentication failed */
    CLIENT_AUTHENTICATION_FAILED(1001, "Client authentication failed"),

    /** Username or password error */
    USERNAME_OR_PASSWORD_ERROR(1002, "Incorrect username or password"),

    /** Unsupported grant type */
    UNSUPPORTED_GRANT_TYPE(1003, "Unsupported authentication mode");

}
